package ru.aslanov.schedule.model;

import javax.jdo.annotations.*;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlID;
import javax.xml.bind.annotation.XmlTransient;

/**
 * Created by IntelliJ IDEA.
 * Created: Nov 25, 2009 5:54:02 PM
 *
 * @author Sergey Aslanov
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Level extends Entity {
    @Persistent
    private String id;
    @Persistent
    @Embedded(members = {@Persistent(name="dbValue", columns=@Column(name="name"))})
    private I18nString name = new I18nString();
    @Persistent
    @Embedded(members = {@Persistent(name="dbValue", columns=@Column(name="url"))})
    private I18nString url = new I18nString();

    @Persistent
    private Schedule schedule;

    public Level() {
    }

    public Level(String id, String name, String url) {
        this.id = id;
        setName(name);
        setUrl(url);
    }

    @Override
    public String toString() {
        return getName();
    }

    @XmlID
    @XmlAttribute
    public String getId() {
        return id != null ? id : getLocalId();
    }

    public void setId(String id) {
        this.id = id;
    }

    @XmlAttribute
    public String getName() {
        return name.getValueWithThreadLang();
    }

    public void setName(String name) {
        this.name.setValueWithThreadLang(name);
    }

    @XmlAttribute(name = "url")
    public String getUrl() {
        return url.getValueWithThreadLang();
    }

    public void setUrl(String url) {
        this.url.setValueWithThreadLang(url);
    }

    @XmlTransient
    public Schedule getSchedule() {
        return schedule;
    }

    public void setSchedule(Schedule schedule) {
        this.schedule = schedule;
    }
}
